<?php
/*
** @introduction: 商品评论
** @author: 杨陈鹏
** @email: yangchenpeng@cdlinglu.com
*/

namespace Admin\Controller\Goods;


use Common\Controller\Admin\CommonController;

class GoodsCommentController extends CommonController
{
    /*
    ** @introduction: 评论列表
    ** @author: 杨陈鹏
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function lists()
    {


        $logic = D('Common/GoodsComment','Logic');

        $this->page = I('post.page',1);
        $this->nums = 20;

        $this->type = I('param.type',false);

        $where = [];

        if($this->type)
            $where['type'] = $this->type;


        $data = $logic::getData($where,'*', 'create_time desc', $this->page, $this->nums);

        $this->data = $data['data'];

        $this->total = $data['total'];

//        echo '<pre>';
//
//        var_dump($this->data);
//        exit;

        $this->display();

    }
    /*
    ** @introduction: 删除评论
    ** @author: 杨陈鹏
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function delete()
    {

        $id = I('post.id');

        $logic = D('Common/GoodsComment','Logic');

        if($logic::$model->where(['id' => $id])->delete()){

            //删除评论回复
            $logic::$model_replay->where(['goods_comment_id' => $id])->delete();

            $this->ajaxReturn(['code' => 200, 'msg' => '删除成功!']);

        }

        $this->ajaxReturn(['code' => 300, 'msg' => '删除失败!']);


    }
    /*
    ** @introduction: 评论回复
    ** @author: 杨陈鹏
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function reply()
    {

        $id = I('post.id');

        $content = I('post.content');

        $logic = D('Common/GoodsComment','Logic');

        $data['goods_comment_id'] = $id;
        $data['content'] = $content;
        $data['create_time'] = NOW_TIME;
        $data['username'] = $this->userinfo['username'];

        if($logic::$model_replay->add($data))
            $this->ajaxReturn(['code' => 200, 'msg' => '回复成功!']);

        $this->ajaxReturn(['code' => 300, 'msg' => '回复失败!']);


    }
    /*
    ** @introduction: 删除评论回复
    ** @author: 杨陈鹏
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function deleteReply()
    {

        $id = I('post.id');


        $logic = D('Common/GoodsComment','Logic');

        if($logic::$model_replay->where(['id' => $id])->delete())
            $this->ajaxReturn(['code' => 200, 'msg' => '删除成功!']);

        $this->ajaxReturn(['code' => 300, 'msg' => '删除失败!']);


    }

}